/****************************************************************************
 * Copyright (C) 2012 Dj_Skual
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************************/
#include "gui_blockbox.h"
#include "../Themes/CTheme.h"

/**
 * Constructor for the GuiBlockBox class.
 */
GuiBlockBox::GuiBlockBox(std::string t)
	: GuiFrame(0, 0)
{
	if(t.empty())
		t = "????";
	
	blockboxSide = Resources::GetImageData("manage_save_block_side.png");
	blockboxTile = Resources::GetImageData("manage_save_block_tile.png");
	
	leftImage = new GuiImage(blockboxSide);
	tileImage = new GuiImage(blockboxTile);
	rightImage = new GuiImage(blockboxSide);
	rightImage->SetAngle(180);
	
	int tile_cnt = 0;
	text = new GuiText(t.c_str(), 28, thColor("r=255 g=255 b=255 a=255 - manage windows text color"));
	tile_cnt = ((text->GetTextWidth() - 12) / tileImage->GetWidth()) + 5;
	if (tile_cnt < 0)
		tile_cnt = 0;
	
	tileImage->SetPosition(leftImage->GetWidth(), 0);
	tileImage->SetTileHorizontal(tile_cnt);
	rightImage->SetPosition(leftImage->GetWidth() + tile_cnt * tileImage->GetWidth(), 0);
	
	height = leftImage->GetHeight();
	width = leftImage->GetWidth() + tile_cnt * tileImage->GetWidth() + rightImage->GetWidth();
	
	Append(leftImage);
	Append(tileImage);
	Append(rightImage);
	Append(text);
}

/**
 * Destructor for the GuiBlockBox class.
 */
GuiBlockBox::~GuiBlockBox()
{
	RemoveAll();
	
	Resources::Remove(blockboxSide);
	Resources::Remove(blockboxTile);
	
	delete leftImage;
	delete tileImage;
	delete rightImage;
	
	delete text;
}
